package com.alex.goods.controller;

import com.alex.core.entity.ApiResponse;
import com.alex.goods.entity.dto.CategoryQueryDTO;
import com.alex.goods.entity.dto.CategorySaveDTO;
import com.alex.goods.entity.dto.CategoryUpdateDTO;
import com.alex.goods.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author cb
 * @date 2019/11/13 11:38
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PostMapping("/save")
    public ApiResponse save(@Valid @RequestBody CategorySaveDTO request) {
        return categoryService.save(request);
    }

    @DeleteMapping("/remove/{id}")
    public ApiResponse remove(@PathVariable Integer id) {
        return categoryService.remove(id);
    }

    @GetMapping("/get/{id}")
    public ApiResponse get(@PathVariable Integer id) {
        return categoryService.get(id);
    }

    @PutMapping("/update")
    public ApiResponse update(@Valid @RequestBody CategoryUpdateDTO request) {
        return categoryService.update(request);
    }

    @GetMapping("/page")
    public ApiResponse page(@ModelAttribute CategoryQueryDTO request) {
        return categoryService.page(request);
    }

}
